<template>
  <div class="login-container">
    <!-- 登录 -->
    <el-form v-show="whichDomShow==='login'" ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" autocomplete="on" label-position="left">
      <div class="title-container">
        <h3 class="title">
          {{ $t('login.title') }}
        </h3>
        <lang-select class="set-language" />
      </div>

      <el-form-item prop="username">
        <span class="svg-container">
          <svg-icon icon-class="user" />
        </span>
        <el-input
          ref="username"
          v-model="loginForm.username"
          :placeholder="$t('login.username')"
          name="username"
          type="text"
          tabindex="1"
          autocomplete="on"
        />
      </el-form-item>

      <el-tooltip v-model="capsTooltip" content="Caps lock is On" placement="right" manual>
        <el-form-item prop="password">
          <span class="svg-container">
            <svg-icon icon-class="password" />
          </span>
          <el-input
            :key="passwordType"
            ref="password"
            v-model="loginForm.password"
            :type="passwordType"
            :placeholder="$t('login.password')"
            name="password"
            tabindex="2"
            autocomplete="on"
            @keyup.native="checkCapslock"
            @blur="capsTooltip = false"
            @keyup.enter.native="handleLogin"
          />
          <span v-if="loginpasswordShow" class="show-pwd" @click="showPwd('passwordType')">
            <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
          </span>
        </el-form-item>
      </el-tooltip>
      <div style="color:#FFF;text-align:right;margin-bottom:30px;"><span style="cursor:pointer" @click="handleForgetPassword"> {{ $t('login.forgetPassword') }}？</span></div>
      <el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleLogin">
        {{ $t('login.logIn') }}
      </el-button>
      <div style="color:#FFF;text-align:center;" @click="handleGoRegist"><span style="cursor:pointer"> {{ $t('login.goRegist') }}</span></div>

      <!-- <div style="position:relative">
        <div class="tips">
          <span>{{ $t('login.username') }} : admin</span>
          <span>{{ $t('login.password') }} : {{ $t('login.any') }}</span>
        </div>
        <div class="tips">
          <span style="margin-right:18px;">
            {{ $t('login.username') }} : editor
          </span>
          <span>{{ $t('login.password') }} : {{ $t('login.any') }}</span>
        </div>

        <el-button class="thirdparty-button" type="primary" @click="showDialog=true">
          {{ $t('login.thirdparty') }}
        </el-button>
      </div> -->
    </el-form>

    <!-- 手机号/邮箱 绑定 -->
    <el-form v-show="whichDomShow==='bindingAccountDom'" ref="confirmValiteForm" :model="confirmValiteForm" class="login-form">
      <div class="title-container" style="text-align:center;font-size:18px;color:#FFF;margin-bottom:40px">
        <div style="margin-bottom:10px;">
          <span :class="bindingType=='PHONE' ? 'active' : ''" @click="handleBindingTab('PHONE')">{{ $t('login.bindingPhone') }}</span>
          <span :class="bindingType=='EMAIL' ? 'active' : ''" style="margin-left:15px;cursor:pointer" @click="handleBindingTab('EMAIL')">{{ $t('login.bindingMail') }}</span>
        </div>
      </div>
      <el-form-item prop="bindingValue">
        <span class="svg-container">
          <svg-icon icon-class="user" />
        </span>
        <span v-if="bindingType==='PHONE'" style="position: relative; left: 11px;color:#FFF">+86</span>
        <el-input
          v-model="confirmValiteForm.bindingValue"
          name="bindingValue"
          type="text"
          tabindex="1"
          autocomplete="on"
          :class="bindingType=='PHONE' ? 'inputClass' : ''"
        />
      </el-form-item>

      <el-form-item class="getCodeWrap" style="position:relative" prop="bindingCode">
        <span class="svg-container">
          <svg-icon icon-class="password" />
        </span>
        <el-input
          v-model="confirmValiteForm.bindingCode"
          name="bindingCode"
          type="text"
          tabindex="1"
          autocomplete="on"
        />
        <div class="getcode">
          <el-button type="primary" size="small" :disabled="isCounting" @click="handleGetCode">{{ countTime | countFilter }}</el-button>
        </div>
      </el-form-item>
      <el-button :loading="bindingBtnLoading" type="primary" style="width:100%;margin:30px 0;" @click.native.prevent="handleBindingAccount">
        {{ $t('login.confirm') }}
      </el-button>
    </el-form>
    <!-- 手机号/邮箱二次验证 -->
    <el-form v-show="whichDomShow==='valiteCofirm'" ref="confirmValiteForm" :model="confirmValiteForm" class="login-form">
      <div class="title-container" style="text-align:center;font-size:18px;color:#FFF;margin-bottom:40px">
        <div v-if="accountType==='PHONE'">
          <div style="margin-bottom:10px;font-size:23px">{{ $t('login.valitePhone') }}</div>
          <span v-if="accountPhoneNumber" style="font-size:14px">+86  {{ accountPhoneNumber }}</span>
        </div>
        <div v-else-if="accountType==='EMAIL'">
          <div style="margin-bottom:10px;font-size:23px">{{ $t('login.valiteMail') }}</div>
          <span style="font-size:14px">{{ accountMailNumber }}</span>
        </div>
        <div v-else-if="accountType==='all'">
          <div style="margin-bottom:10px;">
            <span :class="valiteType=='PHONE' ? 'active' : ''" @click="handleTabValite('PHONE')">{{ $t('login.bindingPhone') }}</span>
            <span :class="valiteType=='EMAIL' ? 'active' : ''" style="margin-left:15px;cursor:pointer" @click="handleTabValite('EMAIL')">{{ $t('login.bindingMail') }}</span>
          </div>
          <span v-if="bindResult" style="font-size:14px"><span v-if="valiteType=='PHONE'" style="margin-right:15px">+86</span>{{ bindResult }}</span>
        </div>
      </div>

      <el-form-item class="getCodeWrap" style="position:relative" prop="bindingCode">
        <span class="svg-container">
          <svg-icon icon-class="password" />
        </span>
        <el-input
          v-model="confirmValiteForm.bindingCode"
          name="bindingCode"
          type="text"
          tabindex="1"
          autocomplete="on"
        />
        <div class="getcode">
          <el-button type="primary" size="small" :disabled="isCounting" @click="handleGetCode">{{ countTime | countFilter }}</el-button>
        </div>
      </el-form-item>
      <el-button :loading="valiteBtnLoading" type="primary" style="width:100%;margin:30px 0;" @click.native.prevent="handleValiteAccount">
        {{ $t('login.confirm') }}
      </el-button>
    </el-form>

    <!-- 重置密码 -->
    <el-form v-show="whichDomShow==='resetpassword'" ref="resetForm" :model="resetForm" class="login-form" :rules="resetRules" label-position="left">
      <div class="title-container">
        <h3 class="title">
          {{ $t('login.forgetPassword') }}
        </h3>
      </div>

      <el-form-item prop="account">
        <span class="svg-container">
          <svg-icon icon-class="user" />
        </span>
        <el-input
          v-model="resetForm.account"
          :placeholder="$t('login.resetPasswordAccount')"
          name="account"
          type="text"
          tabindex="1"
          autocomplete="on"
        />
      </el-form-item>
      <el-form-item class="getCodeWrap" style="position:relative" prop="code">
        <span class="svg-container">
          <svg-icon icon-class="password" />
        </span>
        <el-input
          v-model="resetForm.code"
          name="code"
          type="text"
          tabindex="1"
          autocomplete="on"
        />
        <div class="getcode">
          <el-button type="primary" size="small" :disabled="isCounting" @click="handleGetCode">{{ countTime | countFilter }}</el-button>
        </div>
      </el-form-item>
      <el-button :loading="loading" type="primary" style="width:100%;margin:30px 0;" @click.native.prevent="handleReset">
        {{ $t('login.resetBtn') }}
      </el-button>
    </el-form>

    <!-- 确认重置 -->
    <el-form v-show="whichDomShow==='confirmResetpassword'" ref="confirmResetForm" :model="confirmResetForm" class="login-form" :rules="confirmResetRules">
      <div class="title-container">
        <h3 class="title">
          {{ $t('login.resetBtn') }}
        </h3>
      </div>
      <el-form-item prop="password">
        <span class="svg-container">
          <svg-icon icon-class="password" />
        </span>
        <el-input
          v-model="confirmResetForm.password"
          :placeholder="$t('login.registPassword')"
          name="password"
          :type="confirmResetPasswordType"
          tabindex="1"
          autocomplete="on"
        />
        <span v-if="confirmResetPasswordShow" class="show-pwd" @click="showPwd('confirmResetPasswordType')">
          <svg-icon :icon-class="confirmResetPasswordType === 'password' ? 'eye' : 'eye-open'" />
        </span>
      </el-form-item>
      <el-form-item prop="confirmPassword">
        <span class="svg-container">
          <svg-icon icon-class="password" />
        </span>
        <el-input
          v-model="confirmResetForm.confirmPassword"
          name="confirmPassword"
          :type="confirmResetPasswordTypeTwo"
          tabindex="1"
          autocomplete="on"
        />
        <span v-if="confirmResetPasswordShowTwo" class="show-pwd" @click="showPwd('confirmResetPasswordTypeTwo')">
          <svg-icon :icon-class="confirmResetPasswordTypeTwo === 'password' ? 'eye' : 'eye-open'" />
        </span>
      </el-form-item>
      <el-button :loading="loading" type="primary" style="width:100%;margin:30px 0;" @click.native.prevent="handleConfirmResetPassword">
        {{ $t('login.resetBtnConfirm') }}
      </el-button>
    </el-form>

    <!-- 注册 -->
    <el-form v-show="whichDomShow==='regist'" ref="registForm" :model="registForm" class="login-form" :rules="registRules" label-position="left">
      <div class="title-container">
        <h3 class="title">
          {{ $t('login.registTitle') }}
        </h3>
      </div>

      <el-form-item prop="username">
        <span class="svg-container">
          <svg-icon icon-class="user" />
        </span>
        <el-input
          v-model="registForm.username"
          :placeholder="$t('login.registUserName')"
          name="username"
          type="text"
          tabindex="1"
          autocomplete="on"
        />
      </el-form-item>
      <el-tooltip v-model="capsTooltip" content="Caps lock is On" placement="right" manual>
        <el-form-item prop="password">
          <span class="svg-container">
            <svg-icon icon-class="password" />
          </span>
          <el-input
            :key="passwordTypeRegist"
            ref="password"
            v-model="registForm.password"
            :type="passwordTypeRegist"
            :placeholder="$t('login.registPassword')"
            name="password"
            tabindex="2"
            autocomplete="on"
            @keyup.native="checkCapslock"
            @blur="capsTooltip = false"
          />
          <span v-if="registPasswordShow" class="show-pwd" @click="showPwd('passwordTypeRegist')">
            <svg-icon :icon-class="passwordTypeRegist === 'password' ? 'eye' : 'eye-open'" />
          </span>
        </el-form-item>
      </el-tooltip>
      <el-tooltip v-model="capsTooltip" content="Caps lock is On" placement="right" manual>
        <el-form-item prop="passwordConfirm">
          <span class="svg-container">
            <svg-icon icon-class="password" />
          </span>
          <el-input
            :key="confirmpasswordType"
            ref="passwordConfirm"
            v-model="registForm.passwordConfirm"
            :type="confirmpasswordType"
            :placeholder="$t('login.registPassword')"
            name="passwordConfirm"
            tabindex="3"
            autocomplete="on"
            @keyup.native="checkCapslock"
            @blur="capsTooltip = false"
            @keyup.enter.native="handleLogin"
          />
          <span v-if="registConfirmPasswordShow" class="show-pwd" @click="showPwd('confirmpasswordType')">
            <svg-icon :icon-class="confirmpasswordType === 'password' ? 'eye' : 'eye-open'" />
          </span>
        </el-form-item>
      </el-tooltip>
      <el-checkbox v-model="checked" />  <span style="color: #FFF;margin-left:10px">{{ $t('login.pleaseRead') }}<span style="color:#1890FF;cursor:pointer">{{ $t('login.userAgreement') }}</span>  {{ $t('login.and') }}  <span style="color:#1890FF;cursor:pointer">{{ $t('login.privacy') }}</span></span>
      <el-button :loading="loadingRegist" type="primary" style="width:100%;margin:30px 0;" @click.native.prevent="handleRegist">
        {{ $t('login.registConfrim') }}
      </el-button>
      <div style="width:100%;text-align:center;color:#FFF">{{ $t('login.haveAccount') }}？<span style="color:#FFF;cursor:pointer" @click="goLogin">{{ $t('login.goLogin') }}</span></div>
    </el-form>

    <el-dialog :title="$t('login.thirdparty')" :visible.sync="showDialog">
      {{ $t('login.thirdpartyTips') }}
      <br>
      <br>
      <br>
      <social-sign />
    </el-dialog>
  </div>
</template>

<script>
// import { validUsername } from '@/utils/validate'
import LangSelect from '@/components/LangSelect'
import SocialSign from './components/SocialSignin'
import { tenantRegister } from '@/api/auth'
// import { setToken } from '@/utils/auth'

// import dragVerify from 'vue-drag-verify2'
import i18n from '@/lang'
export default {
  name: 'Login',
  components: { LangSelect, SocialSign },
  filters: {
    countFilter: function(countTime) {
      if (parseInt(countTime) <= 0 || parseInt(countTime) >= 60) {
        var data = i18n.t('login.getCode')
        return data
      } else { return countTime + 's' }
    }
  },
  data() {
    var self = this
    // 登录
    const validateUsername = (rule, value, callback) => {
      if (value.length < 3) {
        callback(new Error(self.$t('login.accountErrorTip')))
      } else {
        callback()
      }
    }
    const validatePassword = (rule, value, callback) => {
      if (value.length < 8) {
        callback(new Error(self.$t('login.passwordErrorTip')))
      } else {
        callback()
      }
    }
    // 注册
    const validateRegistUsername = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error(self.$t('login.accountErrorTip')))
      } else {
        callback()
      }
    }
    const validateRegistPassword = (rule, value, callback) => {
      if (value.length < 8) {
        callback(new Error(self.$t('login.passwordErrorTip')))
      } else {
        if (this.registForm.passwordConfirm.length > 0 && value !== this.registForm.passwordConfirm) {
          callback(new Error(self.$t('login.sameErrorPassword')))
        } else {
          callback()
        }
      }
    }
    const validateRegistConfirmPassword = (rule, value, callback) => {
      if (value.length < 8) {
        callback(new Error(self.$t('login.confirmPasswordErrorTip')))
      } else {
        if (this.registForm.password.length > 0 && value !== this.registForm.password) {
          callback(new Error(self.$t('login.sameErrorPassword')))
        } else {
          callback()
        }
      }
    }
    // 忘记密码
    const validatorAccount = (rule, value, callback) => {
      console.log('忘记密码 ', value)
      if (value.length < 6) {
        callback(new Error(self.$t('login.accountErrorTip')))
      } else {
        callback()
      }
    }
    // 确认重置密码
    const validateConfirmResetPassword = (rule, value, callback) => {
      console.log(value)
      if (value.length < 8) {
        callback(new Error(self.$t('login.passwordErrorTip')))
      } else {
        callback()
      }
    }
    const validateConfirmResetPasswordTwo = (rule, value, callback) => {
      if (value.length < 8) {
        callback(new Error(self.$t('login.passwordErrorTip')))
      } else {
        callback()
      }
    }
    return {
      loginForm: {
        username: 'phonetest',
        password: '00000000'
      },
      registForm: {
        username: '',
        password: '',
        passwordConfirm: ''
      },
      resetForm: {
        account: '',
        code: ''
      },
      confirmValiteForm: {
        bindingValue: '',
        bindingCode: ''
      },
      confirmResetForm: {
        password: '',
        confirmPassword: ''
      },
      loginRules: {
        username: [{ required: true, trigger: 'blur', validator: validateUsername }],
        password: [{ required: true, trigger: 'blur', validator: validatePassword }]
      },
      registRules: {
        username: [{ required: true, trigger: 'blur', validator: validateRegistUsername }],
        password: [{ required: true, trigger: 'blur', validator: validateRegistPassword }],
        passwordConfirm: [{ required: true, trigger: 'blur', validator: validateRegistConfirmPassword }]
      },
      resetRules: {
        account: [{ required: true, trigger: 'blur', validator: validatorAccount }]
      },
      confirmResetRules: {
        password: [{ required: true, trigger: 'blur', validator: validateConfirmResetPassword }],
        confirmPassword: [{ required: true, trigger: 'blur', validator: validateConfirmResetPasswordTwo }]
      },
      passwordType: 'password',
      passwordTypeRegist: 'password',
      confirmpasswordType: 'password',
      capsTooltip: false,
      loading: false,
      showDialog: false,
      redirect: undefined,
      otherQuery: {},
      whichDomShow: 'login',
      registPasswordShow: false,
      registConfirmPasswordShow: false,
      checked: false,
      loginpasswordShow: true,
      isPassing2: false,
      countTime: 0,
      isCounting: false,
      activeName: 'firstName',
      activeBoolean: 'phone',
      accountType: 'PHONE',
      accountNumber: '17600671772',
      bindingType: 'PHONE',
      bindResult: '',
      accountPhoneNumber: '',
      accountMailNumber: '',
      confirmResetPasswordShow: false,
      confirmResetPasswordType: 'password',
      confirmResetPasswordShowTwo: false,
      confirmResetPasswordTypeTwo: 'password',
      loadingRegist: false,
      bindingBtnLoading: false,
      valiteType: 'PHONE',
      valiteBtnLoading: false
    }
  },
  watch: {
    $route: {
      handler: function(route) {
        const query = route.query
        if (query) {
          this.redirect = query.redirect
          this.otherQuery = this.getOtherQuery(query)
        }
      },
      immediate: true
    },
    registForm: {
      handler(val) {
        if (val.password.length > 0) {
          this.registPasswordShow = true
        } else {
          this.registPasswordShow = false
        }
        if (val.passwordConfirm.length > 0) {
          this.registConfirmPasswordShow = true
        } else {
          this.registConfirmPasswordShow = false
        }
      },
      deep: true
    },
    confirmResetForm: {
      handler(val) {
        if (val.password.length > 0) {
          this.confirmResetPasswordShow = true
        } else {
          this.confirmResetPasswordShow = false
        }
        if (val.confirmPassword.length > 0) {
          this.confirmResetPasswordShowTwo = true
        } else {
          this.confirmResetPasswordShowTwo = false
        }
      },
      deep: true
    },
    'loginForm.password': {
      deep: true,
      handler(val) {
        if (val.length > 0) {
          this.loginpasswordShow = true
        } else {
          this.loginpasswordShow = false
        }
      }
    }
  },
  created() {
    // window.addEventListener('storage', this.afterQRScan)
  },
  mounted() {
    console.log(this.bindResult)
  },
  destroyed() {
    // window.removeEventListener('storage', this.afterQRScan)
  },
  methods: {
    handleShowResetPwd() {
      if (this.confirmResetPasswordType === 'password') {
        this.confirmResetPasswordType = ''
      } else {
        this.confirmResetPasswordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    // 忘记密码
    handleForgetPassword() {
      this.whichDomShow = 'resetpassword'
    },
    // 切换绑定方式
    handleTab(type) {
      this.activeBoolean = type
    },
    // 绑定账号切换
    handleBindingTab(type) {
      this.bindingType = type
    },
    // 已绑定状态下切换
    handleTabValite(type) {
      this.valiteType = type
      if (type === 'PHONE') {
        this.bindResult = this.accountPhoneNumber
      } else {
        this.bindResult = this.accountMailNumber
      }
    },
    // 获取验证码
    handleGetCode() {
      this.countTime = 60
      this.timeCountStart()
    },
    // 验证码倒计时
    timeCountStart: function() {
      // Log.info('countTime:', this.countTime)
      // Log.info('isCounting:', this.isCounting)
      var self = this
      window.clock = window.setInterval(function() {
        self.countTime--
        self.isCounting = true
        if (self.countTime < 0) { // 当倒计时小于0时清除定时器
          window.clearInterval(window.clock)
          self.countTime = 60
          self.isCounting = false
        }
      }, 1000)
    },
    // 人机验证
    passcallback2() {
      this.$message({
        message: '验证通过,插槽消失',
        type: 'success'
      })
    },
    // 重置密码
    handleReset() {
      var self = this
      this.$refs.resetForm.validate(valid => {
        if (valid) {
          self.whichDomShow = 'confirmResetpassword'
          return
        } else {
          return false
        }
      })
    },
    // 确定重置密码
    handleConfirmResetPassword() {},
    // 去注册
    handleGoRegist() {
      this.whichDomShow = 'regist'
    },
    // 去登陆
    goLogin() {
      this.whichDomShow = 'login'
    },
    checkCapslock(e) {
      const { key } = e
      this.capsTooltip = key && key.length === 1 && (key >= 'A' && key <= 'Z')
    },
    // 是否显示密码明文
    showPwd(type) {
      console.log(type)
      if (this[type] === 'password') {
        this[type] = ''
      } else {
        this[type] = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    showConfirmPwd() {
      if (this.confirmpasswordType === 'password') {
        this.confirmpasswordType = ''
      } else {
        this.confirmpasswordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.confirmpassword.focus()
      })
    },
    // 确认注册
    handleRegist() {
      var self = this
      this.accountType = 'all'
      this.accountPhoneNumber = ''
      this.accountMailNumber = ''
      this.bindResult = ''
      if (!this.checked) {
        this.$message.warning(self.$t('login.agreementError'))
        return
      }
      this.$refs.registForm.validate(valid => {
        if (valid) {
          self.loadingRegist = true
          tenantRegister(self.registForm).then(res => {
            localStorage.setItem('RegistAccount', res.data.username)
            localStorage.setItem('ticket', res.data.ticket)
            self.loadingRegist = false
            self.whichDomShow = 'bindingAccountDom'
          }).catch(error => {
            self.loadingRegist = false
            console.log(error)
          })
        } else {
          return false
        }
      })
    },
    // 绑定 手机号/邮箱
    handleBindingAccount() {
      var self = this
      this.bindingBtnLoading = true
      var obj = {
        type: this.bindingType,
        contcatInfo: this.confirmValiteForm.bindingValue,
        ticket: localStorage.getItem('ticket'),
        code: this.confirmValiteForm.bindingCode
      }
      this.$store.dispatch('user/userContactInfo', obj).then(res => {
        self.bindingBtnLoading = false
        self.$router.push({ path: '/tenant', query: self.otherQuery })
      }).catch(error => {
        console.log(error)
        self.bindingBtnLoading = false
      })
    },

    // 确认登录
    handleLogin() {
      var self = this
      this.$refs.loginForm.validate(async valid => {
        this.loginForm.verifyCode = '11'
        this.loginForm.verifyId = '22'
        if (valid) {
          this.loading = true
          await this.$store.dispatch('user/login', this.loginForm)
            .then((res) => {
              console.log('res登录结果================》', res)
              const userInfo = res.data.userInfo
              if ((userInfo.phone === '' || userInfo.phone === null) && (userInfo.email === '' || userInfo.email === null)) {
                self.whichDomShow = 'valiteCofirm'
                self.bindResult = ''
                self.accountPhoneNumber = ''
                self.accountMailNumber = ''
              } else {
                console.log('绑定的邮箱====》', userInfo.email)
                self.whichDomShow = 'valiteCofirm'
                if (userInfo.phone !== '') {
                  console.log('========>')
                  // 手机号校验
                  self.accountType = 'PHONE'
                  self.accountPhoneNumber = userInfo.phone
                  console.log('手机号绑定=====》', self.accountPhoneNumber, userInfo.phone)
                }
                if (userInfo.email !== '') {
                  // 邮箱验证
                  self.accountType = 'EMAIL'
                  self.accountMailNumber = userInfo.email
                  console.log('邮箱绑定=====》', self.accountMailNumber, userInfo.email)
                }
                if (userInfo.phone !== '' && userInfo.email !== '') {
                  // 两个绑定
                  self.accountType = 'all'
                  self.bindResult = userInfo.phone
                  console.log('绑定=====》', self.bindResult)
                }
              }
              this.loading = false
              localStorage.setItem('ticket', res.data.ticket)
            })
            .catch((error) => {
              console.log(error)
              this.loading = false
            })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    // 二次验证登录
    handleValiteAccount() {
      var self = this
      this.valiteBtnLoading = true
      var obj = {
        verifyCode: this.confirmValiteForm.bindingCode,
        type: this.bindingType,
        ticket: localStorage.getItem('ticket')
      }
      this.$store.dispatch('user/tenantCheckAgain', obj).then(res => {
        self.valiteBtnLoading = false
        self.$router.push({ path: '/tenant', query: self.otherQuery })
      }).catch(error => {
        console.log(error)
        self.valiteBtnLoading = false
      })
    },
    getOtherQuery(query) {
      return Object.keys(query).reduce((acc, cur) => {
        if (cur !== 'redirect') {
          acc[cur] = query[cur]
        }
        return acc
      }, {})
    }
    // afterQRScan() {
    //   if (e.key === 'x-admin-oauth-code') {
    //     const code = getQueryObject(e.newValue)
    //     const codeMap = {
    //       wechat: 'code',
    //       tencent: 'code'
    //     }
    //     const type = codeMap[this.auth_type]
    //     const codeName = code[type]
    //     if (codeName) {
    //       this.$store.dispatch('LoginByThirdparty', codeName).then(() => {
    //         this.$router.push({ path: this.redirect || '/' })
    //       })
    //     } else {
    //       alert('第三方登录失败')
    //     }
    //   }
    // }
  }
}
</script>

<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg:#283443;
$light_gray:#fff;
$cursor: #fff;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $light_gray;
      height: 47px;
      caret-color: $cursor;

      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #454545;
  }
}
.getCodeWrap {
  position: relative;
  .getcode {
    color: #FFF;
    position: absolute;
    right: 10px;
    top: 7px;
  }
}
.el-tabs__item {
  color: #FFF
}
.inputClass {
  .el-input__inner {
    width: 90%;
    margin-left: 15px
  }
}
</style>

<style lang="scss" scoped>
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;

.login-container {
  min-height: 100%;
  width: 100%;
  background-color: $bg;
  overflow: hidden;

  .login-form {
    position: relative;
    width: 520px;
    max-width: 100%;
    padding: 160px 35px 0;
    margin: 0 auto;
    overflow: hidden;
  }

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;
  .active {
    font-size: 23px;
    color: #1890FF
  }
    span {
      cursor: pointer;
    }
    .title {
      font-size: 26px;
      color: $light_gray;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }

    .set-language {
      color: #fff;
      position: absolute;
      top: 3px;
      font-size: 18px;
      right: 0px;
      cursor: pointer;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }

  .thirdparty-button {
    position: absolute;
    right: 0;
    bottom: 6px;
  }

  @media only screen and (max-width: 470px) {
    .thirdparty-button {
      display: none;
    }
  }
}
</style>
